package sapling.service;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import sapling.aop.WebLogAspect;
import sapling.dao.LogDao;
import sapling.dao.RoleDao;
import sapling.dao.UserDao;
import sapling.model.Log;
import sapling.model.Role;
import sapling.model.User;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * Created by Administrator on 2017/6/21.
 */
@Service
@Transactional
public class RoleService {


    @Autowired
    RoleDao roleDao;
    @Autowired
    UserDao userDao;

    public void saveRole(Long roleid,Long userid) {
        User user=userDao.findOne(userid);
        Role role=roleDao.findOne(roleid);
        if(Objects.nonNull(user)&&Objects.nonNull(role)){
            List<Role> roles=new ArrayList<>();
            roles.add(role);
            user.setRoleList(roles);
            userDao.save(user);
        }
    }
}
